package terra;

import java.io.File;
import java.io.PrintStream;

import terra.managers.ThreadPoolManager;
import terra.network.Client;
import terra.network.PipelineFactory;
import terra.network.Server;
import terra.network.handler.ClientHandler;
import terra.network.packet.PacketHandler;

public class BootStrap {
	public static final byte SERVER_MODE = 0;
	public static final byte CLIENT_MODE = 1;	
	public static byte mode;
	public static File log;
	static PrintStream ps;
	public static void load(byte m, Class<? extends ClientHandler> logic){
		PipelineFactory.setLogicHandler(logic);
		NetworkConfig.loadConfig();
		ThreadPoolManager.getInstance();
		PacketHandler.init();
//		log = new File("debug.txt");
//		int i = 0;
//		while (log.exists())
//			log = new File("debug"+(i++)+".txt");
//		try {
//			log.createNewFile();
//			ps = new PrintStream(log);
//		} catch (FileNotFoundException e) {	e.printStackTrace();
//			} catch (IOException e) {		e.printStackTrace();
//		}
		mode = m;
		if (mode == SERVER_MODE)
			Server.getInstance().init();
		else
			Client.getInstance().init();
	}
	
	
	public static synchronized void addLogMsg(String msg){
		ps.println(msg);
	}

}
